package com.tingyuge.base.design.flyweight;

import java.util.HashMap;

/**
 * 享元 工厂 返回 接口...
 * @Created by xiaodao
 */
public class ChessFlyWeightFactory {

    private static  ChessFlyWeightFactory instance= new ChessFlyWeightFactory();
    ChessFlyWeight chessFlyWeight = new ChessFlyWeightImpl("");

    private static HashMap<String,ChessFlyWeight> map = new HashMap<String, ChessFlyWeight>();

    public  ChessFlyWeight getChess(String color){
        if(map.get(color) !=null){
            return map.get(color);
        }else{
            chessFlyWeight.setColor(color);
            map.put(color,chessFlyWeight);
            return  map.get(color);
        }

    }

    private ChessFlyWeightFactory() {
    }

    public static ChessFlyWeightFactory getInstance(){
        return instance;
    }
}
